package 滑动;

import java.util.Arrays;

public class _1652拆炸弹 {

    /**
     * code = [5,7,1,4], k = 3
     * 
     * @param code
     * @param k
     * @return
     */
    public static int[] decrypt(int[] code, int k) {
        int n = code.length;
        int[] res = new int[n];
        int right = k > 0 ? k + 1 : n;
        k = Math.abs(k);
        int sum = 0;
        for (int i = right - k; i < right; i++) {
            sum += code[i];
        }
        for (int i = 0; i < n; i++) {
            res[i] = sum;
            sum += code[right % n] - code[(right - k) % n];
            right++;
        }
        return res;
    }
    //1,2,3,4,5,6   3

    public static void main(String[] args) {
        Arrays.stream(decrypt(new int[] { 3, 1, 4, 1, 5, 9 }, 3)).forEach(System.out::println);
        //
    }
}
